<?php

class Session
{
	/******Singleton******/

	private static $instance = null;

	public static function getInstance()
	{
		if ( self::$instance == null ) {
			self::$instance = new Session();
		}

		return( self::$instance );
	}
	/*********************/

	public static $sid;
	public static $context;

	public static function start()
	{
		session_start();

		self::$sid = session_id();
	}

	public static function stop()
	{
		session_write_close();
	}

	public static function destroy()
	{
		session_destroy();
	}

	public function __get( $name )
	{
		$result = $_SESSION[$name];

		if( isset( $result ) )
		{
			$result = CoreLib::json_decode( $result );
		}

		return( $result );
	}

	public function __set( $name, $value )
	{
		try {
			$data = CoreLib::json_encode( $value );

			$_SESSION[$name] =  $data;

			session_register($name, $data);
		}
		catch( Exception $ex )
		{

		}
	}
}
?>
